package com.ts.code.creator.creator;

import com.intellij.openapi.command.WriteCommandAction;
import com.ts.code.creator.creator.impl.AdminControllerCreator;
import com.ts.code.creator.creator.impl.AdminParamCreator;
import com.ts.code.creator.creator.impl.AdminServiceCreator;
import com.ts.code.creator.creator.impl.AdminServiceImplCreator;
import com.ts.code.creator.creator.impl.AdminVOCreator;
import com.ts.code.creator.creator.impl.ProviderInterfaceCreator;
import com.ts.code.creator.creator.impl.ProviderReqDTOCreator;
import com.ts.code.creator.creator.impl.ProviderRespDTOCreator;
import com.ts.code.creator.creator.impl.ServiceControllerCreator;
import com.ts.code.creator.creator.impl.ServiceServiceCreator;
import com.ts.code.creator.creator.impl.ServiceServiceImplCreator;
import com.ts.code.creator.util.CreateCodeContext;

import java.util.ArrayList;
import java.util.List;

public class CompositeCodeCreator implements CodeCreator {
    private CreateCodeContext context;
    private List<CodeCreator> codeCreators = new ArrayList<>();

    public CompositeCodeCreator(CreateCodeContext context) {
        this.context = context;

        // 创建类
        codeCreators.add(new AdminVOCreator(context));
        codeCreators.add(new AdminParamCreator(context));
        codeCreators.add(new ProviderReqDTOCreator(context));
        codeCreators.add(new ProviderRespDTOCreator(context));

        // 增加方法
        codeCreators.add(new AdminControllerCreator(context));
        codeCreators.add(new AdminServiceCreator(context));
        codeCreators.add(new AdminServiceImplCreator(context));

        codeCreators.add(new ProviderInterfaceCreator(context));

        codeCreators.add(new ServiceControllerCreator(context));
        codeCreators.add(new ServiceServiceCreator(context));
        codeCreators.add(new ServiceServiceImplCreator(context));
    }

    @Override
    public void create() {
        WriteCommandAction.runWriteCommandAction(context.getProject(), () -> {
            for (CodeCreator codeCreator : codeCreators) {
                try {
                    codeCreator.create();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

}
